;================================================
;Mapper号
    .DEF MAPPER_NUMBER,                 04
    .DEF MAPPER_MIRRORING,              1
;================================================
;MMC3 (Mapper 4) 寄存器常量
    .DEF MAPPER_REG_BANK_CTRL,          $8000
    .DEF MAPPER_REG_BANK_DATA,          $8001
    .DEF MAPPER_REG_MIRRORING,          $A000
    .DEF MAPPER_REG_PRG_RAM_PROTECT,    $A001
    .DEF MAPPER_REG_IRQ_LATCH,          $C000
    .DEF MAPPER_REG_IRQ_RELOAD,         $C001
    .DEF MAPPER_REG_IRQ_DISABLE,        $E000
    .DEF MAPPER_REG_IRQ_ENABLE,         $E001
;================================================
;================================================
    .MACRO MACRO_MAPPER_INIT
    STA MAPPER_REG_IRQ_DISABLE;禁用IRQ
    LDA #MAPPER_MIRRORING ^ $01
    STA MAPPER_REG_MIRRORING;命名表镜像设置
    ;初始化图形bank
    LDX #$05
Chr_Bank_Init
    STX MAPPER_REG_BANK_CTRL
    LDA Chr_Bank_Data,X
    STA MAPPER_REG_BANK_DATA
    DEX
    BPL Chr_Bank_Init
    JMP Chr_Bank_Init_End
Chr_Bank_Data
    .DB $00,$02,$04,$05,$06,$07
Chr_Bank_Init_End
    .ENDM

;================================================
;PRG RAM 操作
;------------------------------------------------
;启用 PRG RAM $6000-7FFF
    .MACRO MACRO_PRG_RAM_ENABLE
        LDA #$80
        STA MAPPER_REG_PRG_RAM_PROTECT
    .ENDM

;------------------------------------------------
;禁用 PRG RAM $6000-7FFF
    .MACRO MACRO_PRG_RAM_DISABLE
        LDA #$40
        STA MAPPER_REG_PRG_RAM_PROTECT
    .ENDM

;================================================
;切页操作
;------------------------------------------------
;切页模式设置为 8KB 切换到 $8000-$9FFF
    .MACRO MACRO_SWITCH_BANK_8000_MODE
        LDA #$06
        STA MAPPER_REG_BANK_CTRL
    .ENDM

;------------------------------------------------
;切页模式设置为 8KB 切换到 $A000-$BFFF
    .MACRO MACRO_SWITCH_BANK_A000_MODE
        LDA #$07
        STA MAPPER_REG_BANK_CTRL
    .ENDM

;------------------------------------------------
;设置切页Bank数据
    .MACRO MACRO_SWITCH_BANK_DATA
    STA MAPPER_REG_BANK_DATA
    .ENDM

;------------------------------------------------
;切页 8KB 切换到 $8000-$9FFF
    .MACRO MACRO_SWITCH_BANK_8000_A
        PHA
        LDA #$06
        STA MAPPER_REG_BANK_CTRL
        PLA
        STA MAPPER_REG_BANK_DATA
    .ENDM

;------------------------------------------------
;切页 8KB 切换到 $A000-$BFFF
    .MACRO MACRO_SWITCH_BANK_A000_A
        PHA
        LDA #$07
        STA MAPPER_REG_BANK_CTRL
        PLA
        STA MAPPER_REG_BANK_DATA
    .ENDM

;================================================
;IRQ操作
;------------------------------------------------
;启用IRQ
    .MACRO MACRO_ENABLE_IRQ
        STA MAPPER_REG_IRQ_ENABLE
    .ENDM
 
;------------------------------------------------
;禁用IRQ
    .MACRO MACRO_DISABLE_IRQ
        STA MAPPER_REG_IRQ_DISABLE
    .ENDM
 
;------------------------------------------------
;响应IRQ
    .MACRO MACRO_ACK_IRQ
        STA MAPPER_REG_IRQ_DISABLE
        STA MAPPER_REG_IRQ_ENABLE
    .ENDM
 